package RoomManageModelServerTest.fakeTest;

import java.rmi.RemoteException;

import model.roomManagement.Implementation.Server;
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ServerTest {
	Server server;
	int creatRoomId;
	@Before
	public void setUp() throws Exception {
		server=new Server();
	}
	@After
	
	 @Test
	public void tsetLoginCheck(){
		try {
			assertEquals(1,server.loginCheck(1, "1"));//正确登录
			assertEquals(0,server.loginCheck(1, "2"));//帐号密码错误
		} catch (RemoteException e) {
		
			assertTrue(e.getMessage().endsWith("RemoteException"));
		}

	}
	@Test
	
	public void  testCreatRoom(){
		try {
			creatRoomId=server.creatRoom(1, "subject", "password");
			assertTrue((-1!=creatRoomId));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void  testDeleteRoom(){
		try {
			assertFalse(server.deletRoom(2, creatRoomId));
			assertTrue(server.deletRoom(1, creatRoomId));
			assertFalse(server.deletRoom(1, creatRoomId));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void testUserEnter(){
		try {
			
			assertTrue(server.userEnter(1, 108));
			assertFalse(server.userEnter(1, 888));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void testUserJoin(){
		try {
			
			assertTrue(server.userJoin(1, 111, "test"));//success join
			assertFalse(server.userJoin(111, 111, "test"));//already join
			assertFalse(server.userJoin(111, 111, "t"));//wrong password

		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void testUserQuit(){
		try {
			
			assertTrue(server.userQuit(111, 111));//success quit
			assertFalse(server.userQuit(1, 111));//not join yet


		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void testChangePassword(){
		try {
			
			assertTrue(server.changePassWord(111, "test", "t"));
			assertFalse(server.changePassWord(111, "test", "t"));


		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
